package Controll;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Dao.User;

public class CountUsersServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	public static int num = 0;
	public static String username = null;

	public CountUsersServlet() {
		super();
	}

	public static Set<User> list = new HashSet<>();

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ServletContext application = this.getServletContext();
		Integer yournumber = new Integer(0);
		yournumber = (Integer) application.getAttribute("Count");
		System.out.println(yournumber);
		HttpSession session = request.getSession();
		if (!session.isNew()) {
			num++;
		}
		User user = new User();
		username = request.getParameter("urname");
		System.out.println(username);
		user.setName(username);
		list.add(user);
		session.setAttribute("name", username);
		request.getRequestDispatcher("index.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
